/*
 * @(#)Initializer.java
 * 
 * Copyright(C) 2004 Yujin Kim
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.netexplode.jtunes.client.player;

import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;

import javax.jmdns.JmDNS;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.netexplode.jtunes.Constants;
import com.netexplode.jtunes.model.player.PlayerManager;
import com.netexplode.jtunes.protocol.jmdns.DaapListener;

/**
 * <code>Initializer</code> represents .....
 * 
 * @author ykim
 * @version $Revision: 1.4 $
 * @since 0.1
 */
public class Initializer {
    private static final Log log = LogFactory.getLog(Initializer.class);

    private final static String ROOT_DIR = "/Users/ykim/Music/iTunes/iTunes Music";

    // private final static String ROOT_DIR = "/Users/ykim/Music/iTunes/iTunes
    // Music";

    private final static String BASE_DIR1 = ROOT_DIR
            + "/Compilations/Witch Hunter Robin Original Sound Score";

    private final static String BASE_DIR2 = ROOT_DIR + "/Yes";

    private final static String BASE_DIR3 = ROOT_DIR + "/The Cranberries";

    private final static String BASE_DIR4 = ROOT_DIR + "/Sade";

    private final static String IPOD_DIR = "/media/usbdisk/iPod_Control";

    public Initializer() {

        // search for itunes hosts
        try {
            final InetAddress inet = InetAddress.getLocalHost();
            final JmDNS jmdns = new JmDNS(inet);
            jmdns
                    .addServiceListener(
                            Constants.DAAP_SERVICE,
                            new DaapListener());
        }
        catch (UnknownHostException e) {
            e.printStackTrace();
        }
        catch (IOException e1) {
            e1.printStackTrace();
        }

        try {
            PlayerManager.getInstance(new String[] {
                    "Compilations",
                    "Yes",
                    "The Cranberries",
                    "Sade",
                    "iPod" }, new String[] {
                    BASE_DIR1,
                    BASE_DIR2,
                    BASE_DIR3,
                    BASE_DIR4,
                    IPOD_DIR });
        }
        catch (IOException e) {
            log.fatal(e, e);
            System.exit(1);
        }

        // // loading up files is done in a seperate thread
        // new Thread() {
        // public void run() {
        // try {
        // PlayerManager.getInstance(new String[] { "Compilations",
        // "iPod" }, new String[] { BASE_DIR1, IPOD_DIR });
        // } catch (IOException e) {
        // log.fatal(e, e);
        // System.exit(1);
        // }
        // }
        // }.start();

    }
}